package cn.dao;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

import java.security.PublicKey;
@Aspect
@Component("nxxx")
public class adsa {
    @Pointcut("execution(* cn.dao..*.save(..))")
    public void sun(){}

    @Before("sun()")
    public void asa(JoinPoint jp){
        System.out.println("没有什么大事！");
    }

    @AfterReturning(pointcut = "sun()" , returning = "ret")
    public void nnx(JoinPoint jp,Object ret){
        System.out.println("真的C!");
    }
    @AfterThrowing(pointcut = "sun()", throwing = "e")
    public void nxn(JoinPoint jp,RuntimeException e){
        System.out.println("报错了");
    }
    @After("sun()")
    public void jxx(JoinPoint jp){
        System.out.println("dfsdfs");
    }
    @Around("sun()")
    public void nxna(ProceedingJoinPoint jp){
        System.out.println("方法执行前");
            try {
                Object nn = jp.proceed();
                System.out.println("方法执行后");
            } catch (Throwable throwable) {
                System.out.println("方法出现异常");
                throwable.printStackTrace();
            }finally {
                System.out.println("方法执行结束");
            }
    }
}
